class Project extends Activity{

    Date startDate
    Date endDate
    
    
    static hasMany = [budgets : Budget]

    static constraints = {
        amountOfHour(nullable:true)
        startDate(nullable:false,validator: {
            val, obj ->
            val < obj.properties['endDate']
            }
        )
        budgets(nullable:true)
        endDate(nullable:false,validator: {
            val, obj ->
            val > obj.properties['startDate']
            }
        )
    }
    /* Get the budget of the year given in parameters
     * If it doesn't exist, let's create it and return it
     * */
    public Budget budget(int year){
        for(Budget b in budgets){
            if(b?.year == year){
                return b;
            }
        }
        Budget b = new Budget(year:year);
        this.addToBudgets(b);
        return b;
    }

    public Budget currentBudget(){
        Date d = new Date();
        return this.budget(d.getYear());
    }

    /* Add employee to project */
     public void addEmployee(Employee e){
        Date d = new Date();
        if(e != null){
            Whoa w = new Whoa(member:e, year:d.getYear(), hours:0, worksInProject:this);
            this.addToAmountOfHour(w);
        }
        else{
            System.out.println("Något gick fel:" + e)
        }
    }

    public Float calcTotalCost(){
        return 1.0
    }

    public Float calcTotalIncome(){
        return 1.0
    }

    public Float calcCurrentBalance(){
        return 100
    }

    public Float calcIncomingBalance(){
        return 1000
    }

    //Returns the status of the project based on date
    public String calcStatus()
    {
        Date now = new Date()
        if(this.startDate>now){
           return "Planned"
        }
            

        if(this.endDate < now){
            return "Done"
        }

        if(this.startDate <= now && this.endDate >= now){
            return "Progressing"
        }

      return "Erroneous"
    }

    String toString(){
        return "("+this.activityId+"), "+this.name;
    }
}
